
/**
 * 点击导航栏中的tree,动态加载tab标签
 */
addTab = function(node) {
	  			var menuTab = $('#menuTab').tabs();
	  			if(menuTab.tabs('exists',node.text)) {
	  				menuTab.tabs('select',node.text);
	  			} else {
	  				if(node.attributes.url && node.attributes.url.length > 0) {
	  					menuTab.tabs('add',{
	  						title:node.text,
	  						closable:true,
	  						content:'<iframe src="'+ node.attributes.url +'" frameborder="0" style="border:0;width:100%;height:100%;"></iframe>'
	  					});
	  				} /*else {  
	  					menuTab.tabs('add',{  
			  			    title:node.text,  
			  			    closable:true,  
			  			    content:'未实现' 
		  			    });
	  				}*/
	  			}
	  		}


/**
 * 将form表单的值序列化成对象
 * @param {Object} form
 * @memberOf {TypeName} 
 * @return {TypeName} 
 */
serializeObject = function(form) {
	var o = {};
	$.each(form.serializeArray(),function(index){
		if(o[this['name']]) {
			o[this['name']] = o[this['name']] + "," + this['value'];
		} else {
			o[this['name']] = this['value'];
		}
	});
	return o;
}

/**
 * 添加field为可编辑
 * 让field不可编辑
 */
$.extend($.fn.datagrid.methods, {
	addEditor: function(jq, param){
		if(param instanceof Array) {
			$.each(param, function(index, item) {
				var e = $(jq).datagrid('getColumnOption', item.field);
				e.editor = item.editor;
			});
		} else {
			var e = $(jq).datagrid('getColumnOption', param.field);
			e.editor = param.editor;
		}
	},
	removeEditor: function(jq, param){
		if(param instanceof Array) {
			$.each(param, function(index, item) {
				var e = $(jq).datagrid('getColumnOption', item);
				e.editor = {};
			});
		} else {
			var e = $(jq).datagrid('getColumnOption', param);
			e.editor = {};
		}
	}
});

/**
 * 扩展datetimebox为datagrid的editors
 */
$.extend($.fn.datagrid.defaults.editors, {
	datetimebox: {
		init:function(container, options) {
			var editor = $('<input />').appendTo(container);
			options.editable = false;
			editor.datetimebox(options);
			return editor;
		},
		getValue:function(target) {
			return $(target).datetimebox('getValue');
		},
		setValue :function(target, value) {
			$(target).datetimebox('setValue', value);
		},
		resize:function(target, width) {
			$(target).datetimebox('resize', width);
		}
	}
});

/**
 * 扩展combogrid为datagrid的editors
 */
$.extend($.fn.datagrid.defaults.editors, {
    combogrid: {
        init: function(container, options){
            var input = $('<input type="text" class="datagrid-editable-input">').appendTo(container);
            input.combogrid(options);
            return input;
        },
        destroy: function(target){
            $(target).combogrid('destroy');
        },
        getValue: function(target){
            return $(target).combogrid('getValue');
        },
        setValue: function(target, value){
            $(target).combogrid('setValue', value);
        },
        resize: function(target, width){
            $(target).combogrid('resize',width);
        }
    }
});

/**
 * validatbox 扩展代码
 * @param {Object} value
 * @param {Object} param
 * @return {TypeName} 
 */
$.extend($.fn.validatebox.defaults.rules, {
		eqPassword: {
			validator: function(value, param){
				return value == $(param[0]).val();
			},
			message: "密码不一致"
		}
});

//在layout的panle全局配置中,增加一个onCollapse处理title
$.extend($.fn.layout.paneldefaults, {
	onCollapse : function () {
		//获取layout容器
		var layout = $(this).parents("div.layout");
		//获取当前region的配置属性
		var opts = $(this).panel("options");
		//获取key
		var expandKey = "expand" + opts.region.substring(0, 1).toUpperCase() + opts.region.substring(1);
		//从layout的缓存对象中取得对应的收缩对象
		var expandPanel = layout.data("layout").panels[expandKey];
		//针对横向和竖向的不同处理方式
		if (opts.region == "west" || opts.region == "east") {
			//竖向的文字打竖,其实就是切割文字加br
			var split = [];
			for (var i = 0; i < opts.title.length; i++) {
				split.push(opts.title.substring(i, i + 1));
			}
			expandPanel.panel("body").addClass("panel-title").css("text-align", "center").html(split.join("＜ｂｒ＞"));
		} else {
			expandPanel.panel("setTitle", opts.title);
		}
	}
});
